﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NGourd.Core.Runners;
using NGourd.Core.Reports;

namespace NGourd.Core.Plans
{
    abstract class LifecycleScenarioStep : IPlan
    {
        protected readonly StepLibrary stepLibrary;
        private readonly string name;

        public LifecycleScenarioStep(StepLibrary stepLibrary, string name)
        {
            this.stepLibrary = stepLibrary;
            this.name = name;
        }

        protected abstract void Execute();

        #region IPlan Members

        public ReportNode Execute(bool skipExecution)
        {
            if (skipExecution)
            {
                return new ReportNode(ReportTarget.LIFECYCLE_STEP, name) { Status = ReportStatus.SKIPPED };
            }

            try
            {
                Execute();
                return new ReportNode(ReportTarget.LIFECYCLE_STEP, name) { Status = ReportStatus.PASSED };
            }
            catch( Exception ex)
            {
                return new ReportNode(ReportTarget.LIFECYCLE_STEP, name + Environment.NewLine + ex.ToString()) { Status = ReportStatus.FAILED };
            }
        }

        #endregion
    }
}
